// 定义记分牌 类
class ScorePanel {
  // 记录分数和等级
  score = 0;
  level = 1;

  scoreEle: HTMLElement;
  levelEle: HTMLElement;

  // 设置一个变量限制等级
  maxLevel: number;

  // 设置多少分升级
  upScore: number;

  constructor(maxLevel: number = 10, upScore: number = 2) {
    this.maxLevel = maxLevel;
    this.upScore = upScore;
    // 从 score 的类型里去除了 null 和 undefined
    // 用作类型断言
    this.scoreEle = document.getElementById('score')!;
    this.levelEle = document.getElementById('level')!;
  }

  // 设置加分方法
  handleAddScore() {
    this.scoreEle.innerHTML = ++this.score + '';
    console.log(`this.score`, this.score);
    if (this.score % this.upScore === 0) {
      this.handleLevelUp();
    }
  }

  // 提升等级的方法
  handleLevelUp() {
    if (this.level < this.maxLevel) {
      this.levelEle.innerHTML = ++this.level + '';
      console.log(`this.level`, this.level);
    }
  }
}

export default ScorePanel;
